<template>
  <div id="con">
    <header>
      <div class="top">
        <img src="../../../assets/img/index (3).png" class="inp1" />
        <img src="../../../assets/img/index (4).png" alt="#" />
        <div>
          <i class="icon-sousuo iconfont" @click="toSearch()"></i>
          <input type="text" placeholder="按内容搜索" />
        </div>
        <img src="../../../assets/img/index (5).png" class="inp2" />
      </div>
      <ul class="bottom">
        <li v-for="(item) in arr" :key="item.id" @click="foodList(item.id)">{{item.catename}}</li>
        <li>
          <img src="../../../assets/img/index (7).png" alt="#" />分类
        </li>
      </ul>
    </header>
    <div class="banner">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item id="banner" v-for="item in banner" :key="item.id">
          <img :src="$pre+item.img" alt />
        </van-swipe-item>
      </van-swipe>
      <ul>
        <li>
          <img src="../../../assets/img/index (9).png" alt />
          <p>限时秒杀</p>
        </li>
        <li>
          <img src="../../../assets/img/index (10).png" alt />
          <p>畅销商品</p>
        </li>
        <li>
          <img src="../../../assets/img/index (11).png" alt />
          <p>品质大牌</p>
        </li>
        <li>
          <img src="../../../assets/img/index (12).png" alt />
          <p>小U自营</p>
        </li>
        <li>
          <img src="../../../assets/img/index (13).png" alt />
          <p>积分商城</p>
        </li>
      </ul>
    </div>
    <main>
      <div class="content1">
        <img src="../../../assets/img/index (14).png" alt />
        <div>
          <img src="../../../assets/img/index (15).png" alt />
          <img src="../../../assets/img/index (16).png" alt />
        </div>
      </div>
      <div class="content2">
        <div class="zi">
          <p>双11尖货预购</p>
          <p>畅销全球</p>
        </div>
        <div class="tu">
          <img src="../../../assets/img/index (17).png" alt />
          <img src="../../../assets/img/index (18).png" alt />
          <img src="../../../assets/img/index (19).png" alt />
          <img src="../../../assets/img/index (20).png" alt />
        </div>
      </div>
    </main>
    <footer>
      <div class="footerTop">
        <div v-for="(item,index) in seckill" :key="item.id" @click="change(index)">{{item.title}}</div>
      </div>
      <div class="footerMain">
        <div class="clearfix" v-for="item in list" :key="item.id" @click="toDetail(item.id)">
          <img :src="$pre+item.img" alt class="fl" />
          <div class="fl">
            <p>{{item.goodsname}}</p>
            <h3>价格{{item.price}}</h3>
            <p>原价{{item.market_price}}</p>
            <p>
              <button @click.stop="addShop(item.id)">立即抢购</button>
            </p>
          </div>
        </div>
      </div>
    </footer>
  </div>
</template>

<script>
import {
  reqBanner,
  reqHomeCate,
  seckill,
  reqHomeGoods,
  reqAdd
} from "../../../http/api.js";
import {Toast} from "vant"
export default {
  data() {
    return {
      arr: [],
      banner: [],
      seckill: [],
      list: [],
      n: 0
    };
  },
  methods: {
    addShop(id){
        reqAdd({
          uid:JSON.parse(localStorage.getItem("user")).uid,
          goodsid:id,
          num:1,
          authorization:JSON.parse(localStorage.getItem("user")).token
        }).then(res=>{
          if(res.data.code==200){
            Toast(res.data.msg)
          }
        })
      },
    toSearch() {
      this.$router.push("/search");
    },
    foodList(id) {
      this.$router.push("/foodList?id=" + id+"&type=1");
    },
    change(index) {
      reqHomeGoods().then(res=>{
      this.list=res.data.list[index].content
    });
    },
    toDetail(id){
      this.$router.push("/detail?id="+id)
    }
  },
  mounted() {
    reqBanner().then(res => {
      this.banner = res.data.list;
    });
    reqHomeCate().then(res => {
      this.arr = res.data.list;
    });
    seckill().then(res => {
      this.seckill = res.data.list;
    });
    reqHomeGoods().then(res=>{
      this.list=res.data.list[this.n].content
    });
  }
};
</script>

<style scoped>
/* .footerMain{
  width: 80vw;
} */
.footerMain {
  background-color: #e6e6e6;
}
.footerMain .clearfix {
  width: 80vw;
  margin: 0.2rem auto;
  background-color: white;
  /* box-shadow: black; */
  padding: 0.2rem;
  border-radius: 0.2rem;
}
.footerMain .clearfix h3{
  color: orange;
}
.footerMain .clearfix img {
  width: 1.5rem;
  height: 1.7rem;
  margin-right: 0.5rem;
}
.footerMain .clearfix p,.footerMain .clearfix h3 {
  margin: 0.1rem;
}
.footerMain .clearfix button {
  padding: 0.1rem 0.2rem;
  background-color: rgb(255, 157, 87);
  color: white;
}
.footerTop {
  display: flex;
  margin: 0.2rem;
}
.footerTop div {
  flex: 1;
  text-align: center;
  background-color: coral;
  margin: 0 0.2rem;
  padding: 0.1rem 0;
  color: white;
}
#con {
  margin-bottom: 1rem;
}
#banner {
  height: 4rem;
  margin: 0.3rem auto;
}
#banner img {
  width: 100%;
  height: 100%;
}
header {
  background: linear-gradient(to bottom, #ff6040, #ff9287);
}
header .top {
  display: flex;
  height: 0.9rem;
  justify-content: space-around;
  align-items: center;
}
header .top img {
  width: 1.82rem;
  height: 0.48rem;
}
header .top .inp1 {
  width: 0.37rem;
  height: 0.48rem;
}
header .top .inp2 {
  width: 0.4rem;
  height: 0.4rem;
}
header .top div {
  width: 3.4rem;
  border: 2px solid #e6e6e6;
  border-radius: 6px;
  background-color: white;
  display: flex;
  align-items: center;
}
header .top div > input:nth-child(1) {
  width: 0.32rem;
  height: 0.32rem;
  background-size: 100%;
  margin: 0 0.15rem;
}
header .top div > input:nth-child(2) {
  width: 2.4rem;
  height: 0.6rem;
  font-size: 0.26rem;
}
header .bottom {
  height: 0.66rem;
  display: flex;
  justify-content: space-around;
  position: relative;
  overflow: hidden;
  box-shadow: 0px 0.12rem 0.12rem #ffd7d0;
}
header .bottom li {
  color: white;
  line-height: 0.63rem;
  font-size: 0.24rem;
}
header .bottom li:nth-of-type(8) {
  position: absolute;
  right: 0;
  width: 1.2rem;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  background-color: #ff887d;
  box-shadow: -2px 0px 3px #f76b5d;
  height: 0.66rem;
  font-size: 0.24rem;
}
header .bottom li:nth-of-type(8) img {
  width: 0.26rem;
  height: 0.26rem;
}
.banner > img {
  width: 6.7rem;
  height: 3.9rem;
  margin: 0.2rem auto;
  box-shadow: 0 0.1rem 0.15rem #ffdfd9;
}
.banner ul {
  height: 1.5rem;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.banner ul li {
  width: 1rem;
  text-align: center;
}
.banner ul li img {
  width: 0.6rem;
  height: 0.62rem;
  margin: 0 auto 0.15rem;
}
.banner ul li p {
  font-size: 0.18rem;
  color: gray;
}
main {
  padding: 0.2rem;
  background-color: #f2f2f2;
}
main .content1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
main .content1 > img {
  width: 3.5rem;
  height: 3.5rem;
}
main .content1 div img {
  width: 3.5rem;
  height: 1.7rem;
}
main .content2 {
  background-color: white;
  width: 7.1rem;
  margin: 0.15rem auto 0;
}
main .content2 .zi {
  width: 6.7rem;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 0.84rem;
}
main .content2 .tu {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 6.7rem;
}
main .content2 .tu img {
  width: 1.6rem;
}
.icon-sousuo {
  font-size: 0.3rem;
  margin: 0 0.1rem;
}
</style>